/*  Signal.c - Demonstrate how to handle a signal. */

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void sigsegv_handler(int sig) {
    printf("SIGSEGV received.\n");
    exit(0);
}

int main(int argc, char * argv[]) {
    int *null_pointer=(int *)NULL;
    signal(SIGSEGV,sigsegv_handler);
    printf("About to segfault:\n");
    *null_pointer=0;
    printf("Why didn't we crash?\n");
    return 1;
}

/*  Please note that the checks on the return value of the system calls
    have been omitted to avoid cluttering the code. However, system calls
    can and will fail, in which case the results are unpredictable. */
